// main.cpp
// Header file for spectral processing dialog using Qt4 and Qwt packages
// Author: Garreth Ruane

#ifndef PLOTDIALOG_H
#define PLOTDIALOG_H

#include <sys/stat.h>
#include <QDialog>
#include <qwt_plot.h>
#include <qwt_plot_curve.h>
#include <qwt_plot_picker.h>
#include <qwt_picker_machine.h>
#include <qwt_plot_zoomer.h>
#include <qwt_plot_marker.h>
#include <qwt_symbol.h>

class QwtPlot;
class QwtPlotCurve;
class QwtPlotCanvas;
class QwtPlotPicker;
class QwtPlotZoomer;
class QwtPlotMarker;
class QwtSymbol;
class QDoubleSpinBox;
class QPlainTextEdit;
class QTextEdit;
class QPushButton;
class QLabel;
class QLineEdit;
class QFont;
class QwtText;
class QRadioButton;
class QCheckBox;
class QFileDialog;
class QMenuBar;
class QMenu;

class PlotDialog : public QDialog
{
	Q_OBJECT
	
	public:
		PlotDialog(QWidget *parent = 0);
		
	private slots:
		void updateAxis();
		void updateAfterZoom(const QRectF &rect);
		void loadfile();
		void usepoints(bool);
		void useranges(bool);
		void usemouse(bool);
		void enablecpointmarkers(bool);
		void enablebandcenterline(bool);
		void enableactualminmarker(bool);
		void browse();
		void removecontinuum();
		void calculate();
		void pointRegister(const QPointF &pos);
		void printPlotDataToFile();
		void printtofile();
		void printtostd();
		void cleartext();
		void clearoutput();
		void resetaxes();
		void reset();
		void quit();
				
	private:
		QMenuBar *menubar;
		QMenu *filemenu;
		QMenu *optionsmenu;
		QMenu *viewmenu;	
	
		QAction *quitaction;
		QAction *cpointsaction;
		QAction *resetaxesaction;
		QAction *bandcenterlineaction;
		QAction *actualminaction;
		
		QwtPlot *plot;
		QwtPlotCurve *data;
		QwtPlotCurve *rcdata;
		QwtPlotCanvas *pcanvas;
		QwtPlotPicker *ppicker;
		QwtPlotZoomer *pzoomer;
		// Continuum Line & Markers
		QwtPlotMarker *marker1;
		QwtPlotMarker *marker2;
		QwtPlotMarker *marker3;
		QwtPlotMarker *marker4;
		QwtPlotMarker *contline;
		QwtPlotMarker *contmarker1;
		QwtPlotMarker *contmarker2;
		
		// Calculation Markers
		QwtPlotMarker *bandcenterline;
		QwtPlotMarker *actualminmarker;
		
		
		QFileDialog *filedialog;
		QFileDialog *savedialog;
		QDoubleSpinBox *spinbox1;
		QDoubleSpinBox *spinbox2;
		QDoubleSpinBox *spinbox3;
		QDoubleSpinBox *spinbox4;
		QTextEdit *entry;
		QPlainTextEdit *display;
		QPushButton *browsebutton;
		QPushButton *calcbutton;
		QPushButton *rcbutton;		
		QPushButton *clearbutton;
		QPushButton *clearoutputbutton;
		QPushButton *plotdatatofilebutton;
		QPushButton *tofilebutton;
		QPushButton *tostdoutbutton;
		QPushButton *resetbutton;
		
		QLabel *inputfilelabel;
		QLabel *radiolabel;
		QLabel *inputlabel;
		QLabel *outputlabel;
		QLineEdit *inputfilelineedit;
		QPushButton *inputfileloadbutton;
		QRadioButton *pointsradiobutton;
		QRadioButton *rangesradiobutton;
		QCheckBox *selectbox;
		QwtText *xlabel;
		QString *strdisplay;
		QString *strbandmin;
		QString *strbanddepth;
		QString *strfwhm;
		QString *strasym;
		QString *strutil;
		char *filename;
		QFont *font;
		double xmin,xmax,ymin,ymax;
		double minrcx, minrc, maxrc;
		int usingranges;
		bool cpointmarkers;
		bool showbandcenterline;
		bool showactualminmarker;
		int numOfChannels;
		int numOfBands;
		std::vector<double> w;
		std::vector<double> d;
		std::vector<double> newd;
		std::vector<double> e;
		double bandMin; 	// Minimum data point in the band range. 
		double bandDepth; 	// Depth of the band.
		double FWHM; 		// The full width at half maximum of the band. 
		double asym; 		// The calculated asymmetry of the band. 
		struct stat stats;
};

#endif
